<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
</head>
<body>
<h1>登录页面</h1>

<form id="loginForm">

  账号：<input type="text" name="username"/><br/>
  密码：<input type="password" name="password"/><br/>
  验证码：<input type="text" name="userCode"/><img src="user?action=doDrawCode" width="120px" height="30px" onclick="refresh()"><a href="#" onclick="refresh()">刷新</a><br/>
  记住我：<input type="checkbox" name="rememberMe"/><br/>
  角色：
  <select name="role">
    <option value="student">学生</option>
    <option value="teacher">老师</option>
    <option value="admin">管理员</option>
  </select>
  <br/>
  <input id="loginBtn" type="button" value="登录"/>
  <input type="button" value="返回" onclick="goWelcome()"/>
</form>

<script src="js/jquery-1.8.2.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
  function goWelcome(){
    window.location = "welcome.html";
  }

  img = document.getElementsByTagName("img")[0];
  function refresh(){
    img.src = "user?action=doDrawCode&" + new Date();
  }

  $(function (){
    $("#loginBtn").click(function (){
      $.ajax(
              {
                type:"post",
                url:"user?action=doLogin",
                data:$("#loginForm").serialize(),
                async:true,
                success:function (data){
                  if (data == "1"){
                    window.location = "index.html";
                  }else if (data == "-1"){
                    alert("登录失败 -- 账号或密码错误");
                  }else if (data == "-2"){
                    alert("登录失败 -- 验证码错误");
                  }else if(data == "2"){
                    window.location = "adminIndex.html";
                  }
                }
              }
      )

    })
  })

</script>

</body>
</html>